import unittest
from common.header.Header import Headers
from common.login import Login
from common.request import Requests
from pytest_assume.plugin import assume
from common.db import db
from ddt import ddt, file_data
import os
import pytest
from common.backup_roll import db_backup_reset
# @pytest.mark.backup_tables(["products"])
@ddt
class TestCase:
    # 动态获取路径
    BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
    DATA_FILE = os.path.join(BASE_DIR, 'data', 'data01.yaml')
    print("--->",DATA_FILE)
    @pytest.mark.api
    @file_data(DATA_FILE)
    def test_add_01(self,permissionName,permission,remark):
        login = Login()
        login.login("这是添加权限")
        header = Headers().headers()
        print(header)
        data = {"permissionName": permissionName, "permission":permission , "remark": remark}
        res = Requests(headers=header).post_request(url="/boss/pms/permission/add", data=data)
        print(res.text)
        print(res.url)
        print(res.cookies)

    def test_select_02(self):
        login = Login()
        login.login("这是权限管理列表")
        header = Headers().headers()
        res = Requests(headers=header).get_request(url="/boss/pms/permission/list")
        print(res.text)
        assume(res.status_code == 200)
        # db_conn=test_setup_teardown
        db_conn=db()
        a =db_conn.query("SELECT permission_name FROM pms_permission WHERE permission_name = '刘备1,'")
        data = a
        result = data[0][0]
        assume(result in res.text)
        # db_backup_reset()


if __name__ == '__main__':
    unittest.main()
